package cn.itcast.demo.config;

import cn.itcast.demo.interceptors.LoginInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @Author: taft
 * @Date: 2018-12-8 11:24
 */
@Configuration
public class MvcConfig implements WebMvcConfigurer {

    @Bean
    public LoginInterceptor loginInterceptor(){
        return new LoginInterceptor();
    }


    @Override//把我自己的拦截器添加到系统拦截器组中,添加的时候一定要spring 的bean
    public void addInterceptors(InterceptorRegistry registry) {
        //当请求为 /user的相关信息才会执行
        registry.addInterceptor(loginInterceptor()).addPathPatterns("/user/**");
    }
}
